package com.example.gokchinesefoodmappcdev.service.impl;

import com.example.gokchinesefoodmappcdev.dao.GoodsInfoDao;
import com.example.gokchinesefoodmappcdev.dao.GoodsPicDao;
import com.example.gokchinesefoodmappcdev.entity.dto.GoodsDTO;
import com.example.gokchinesefoodmappcdev.service.GoodsInfoService;
import com.example.gokchinesefoodmappcdev.service.GoodsPicService;
import com.example.gokchinesefoodmappcdev.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GoodsPicServiceImpl implements GoodsPicService {

    @Autowired
    GoodsPicDao goodsPicDao;

    @Override
    public ResultData updatePicInfoByIdAndPicPath(int id, String picPath) {
        int i = goodsPicDao.updatePicInfoByIdAndPicPath(id, picPath);
        if(i>0){
            return new ResultData(0,"操作成功!");
        }

        return new ResultData(500,"操作失败");
    }

    @Override
    public int selectIdByGoodIdAndSkuPath(Integer goodId, String skuPath) {

        int id = goodsPicDao.selectIdByGoodIdAndSkuPath(goodId, skuPath);
        return id;
    }

    @Override
    public ResultData insertGoodsPic(Integer goodId,GoodsDTO goodsInfo) {

        String picPath = goodsInfo.getPicPath();
        int i = goodsPicDao.insertGoodsPic(goodId,picPath);
        if(i>0){
            return new ResultData(0,"操作成功!");
        }

        return new ResultData(500,"操作失败");
    }
}
